﻿using SRB.Tg.Operate;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ExportBridgeCatalog
{
    static class Program
    {
        static string excelPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "ExcelDemo";
        //static async Task Main(string[] args)
        static void Main(string[] args)
        {
            //args = new string[] { "0", "1802595897232498690", "1803362569048506371", @"C:\Users\83460\Desktop\CAD\大理机场" };
            //args = new string[] { "0", "1826101430480424961", "1826102672346730498", @"C:\Users\83460\Desktop\CAD\府谷机场" };
            Run(args);
            Environment.Exit(0);
        }

        private static void Run(string[] paras)
        {
            WriteLogs wl = new WriteLogs();
            wl.writeLogs("开始启动程序", "exelog");
            Console.WriteLine("开始启动程序");
            DateTime beginTime = DateTime.Now;            //获取开始时间
            //Console.WriteLine("程序开始时间：{0}", beginTime);
            Console.WriteLine("导出图纸和CAD文件参数处理");
            wl.writeLogs("导出图纸和CAD文件参数处理", "exelog");
            int result = 0;
            string filePath = "";
            try
            {
                if (paras.Length < 1)
                {
                    result = 0;
                }
                else
                {
                    wl.writeLogs("开始生成图纸，参数:" + paras[0], "exelog");

                    //web端调用时，会传入三个参数，传递后两个即可
                    filePath = ExportBridgeCatalog.DrawingBridgeCatalog(paras[1], paras[2], paras[3]);


                    if (System.IO.File.Exists(filePath))
                    {
                        wl.writeLogs("导出文件路径:" + filePath, "exelog");
                        Console.WriteLine("导出图纸和CAD文件成功:SUCCESS,文件路径:CADFilePath='" + filePath + "'");
                        result = 1;
                    }
                    else
                    {
                        wl.writeLogs("导出图纸和CAD文失败", "exelog");
                        result = 0;
                    }
                }


                if (result == 1)
                {
                    Console.WriteLine("正在导出图纸和CAD文件..");
                    Console.WriteLine("ExportCADFiles:true");
                    wl.writeLogs("ExportCADFiles:true", "exelog");
                }
                else
                {
                    wl.writeLogs("导出图纸和CAD文件失败", "exelog");
                    Console.WriteLine("导出图纸和CAD文件失败！");
                    Console.WriteLine("ExportCADFiles:failed");
                    wl.writeLogs("ExportCADFiles:failed", "exelog");
                }

                DateTime endTime = DateTime.Now;              //获取结束时间  
                TimeSpan oTime = endTime.Subtract(beginTime); //求时间差的函数  
                //Console.WriteLine("程序结束时间：{0}", endTime);
                //输出运行时间。  
                Console.WriteLine("程序的运行时间：{0} 秒", oTime.TotalSeconds);
                //Console.WriteLine("程序的运行时间：{0} 毫秒", oTime.TotalMilliseconds);
            }
            catch (Exception ex)
            {
                wl.writeLogs("ExportCADFiles:Exception，异常原因：" + ex.ToString(), "exelog");
                Console.WriteLine("ExportCADFiles:failed");
                Console.WriteLine(ex);
                //System.Diagnostics.Debug.WriteLine(ex);
                result = 0;
            }
            finally
            {
                Environment.Exit(0);
            }

            Environment.ExitCode = result;

        }
    }
}
